package com.software.demo4;

import com.software.utils.HibernateUtils;
import org.hibernate.Session;
import org.hibernate.Transaction;

public class Run {
    public static void main(String[] args) {
        Run run = new Run();
        //run.save();
        run.get();
    }
    public void save() {
        Session session = HibernateUtils.getSession();
        Transaction transaction = session.beginTransaction();
        User user = new User();
        user.setUserName("hugx");

        Order o1 = new Order();
        o1.setPrice(100.0);

        Order o2 = new Order();
        o2.setPrice(50.0);

        user.getOrderSet().put("o1", o1);
        user.getOrderSet().put("o2", o2);

        session.save(user);

        transaction.commit();
        session.close();
    }
    public void get() {
        Session session = HibernateUtils.getSession();
        Order order = session.get(Order.class, 13);
        System.out.println(order.getUser().getUserName());
        session.close();
    }
}
